#define fexit(s) { fprintf( stderr, "%s\n", s ); exit(1); }
#include "jerasure.h"

int main( int argc, char** argv )
{
	JER_Matrix *matrix;
	int r = atoi( argv[1] );
	int c = atoi( argv[2] );
	int w = atoi( argv[3] );
	JER_Matrix *matrix2;
	JER_Matrix *prod;
	int i, fsize;

	matrix = new JER_Matrix( r, c, w );
	matrix2 = new JER_Matrix( c, r, w );
	prod = new JER_Matrix();

	if( matrix == NULL || matrix2 == NULL )
		fexit( "Matrix could not be allocated." );
	srand48(c);
	fsize = 1 << w;
	for( i = 0; i < r * c; i++ )
	{
		matrix->Set( i/c, i%c, lrand48() % fsize );
		matrix2->Set( i/r, i%r, lrand48() % fsize );
	}
	Prod( matrix, matrix2, prod );
	if( prod != NULL )
		prod->Print();
	else
		fprintf( stderr, "prod could not be allocated\n" );

	return 0;
}
